package org.huawei260.TiKu.ODsuanfa;

import java.util.Arrays;
import java.util.Scanner;
public class B_2023B_3800__回溯第N个排列 {

//	public class Main {
		static int[] fact;

		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			int n = sc.nextInt();
			int k = sc.nextInt();

			fact = new int[n + 1];
			fact[1] = 1;
			for (int i = 2; i <= n; i++) {
				fact[i] = fact[i - 1] * i;
			}

			int[] arr = new int[n];
			for (int i = 0; i < n; i++) arr[i] = i + 1;

			System.out.println(getResult(n, k, arr));
		}

		public static String getResult(int n, int k, int[] arr) {
			if (n == 1) return "1";

			StringBuilder sb = new StringBuilder();

			while (true) {
				int f = fact[n - 1];
				int prefix = arr[(k - 1) / f];
				sb.append(prefix);

				k = k % f;
				if (k == 0) k = f;

				arr = Arrays.stream(arr).filter(ele -> ele != prefix).toArray();
				n--;
				if (k == 1) {
					for (int v : arr) sb.append(v);
					break;
				}
			}

			return sb.toString();
		}
	}